package net.tycmc.cty.ctyms.web.maintAlertManual;

import java.io.IOException;
import java.io.PrintWriter;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import net.tycmc.cty.ctyms.web.Action.BaseActionS2;

public class MaintAlertManualAction extends BaseActionS2 {
	ApplicationContext ctx = new ClassPathXmlApplicationContext(
			"/applicationContext.xml");
	MaintAlertManualService maintAlertManualService = (MaintAlertManualService) ctx
			.getBean("maintAlertManualService");

	public String initMaintAlertManual() {
		//保养计划提醒信息  列表 数量
		int[] Listcount = this.getListCount();
		int count1 = Listcount[0];
		int count2 = Listcount[1];
		int count3 = Listcount[2];
		request.setAttribute("count1", count1);
		request.setAttribute("count2", count2);
		request.setAttribute("count3", count3);
		
		int[] count = this.getCount();
		int count4 = count[0];
		int count5 = count[1];
		int count6 = count[2];
		request.setAttribute("count4", count4);
		request.setAttribute("count5", count5);
		request.setAttribute("count6", count6);
		return "initMaintAlertManual";
	}

	// 保养计划提醒信息  列表 数量
	public int[] getListCount() {
		return maintAlertManualService.getInfoListCount();
	}
	// 保养计划提醒信息表 数量
	public int[] getCount(){
		return maintAlertManualService.getCount();
	}

	// 删除上次统计失败的数据
	public boolean deleteData() {
		return maintAlertManualService.deleteData();
	}

	// 重新执行统计
	public void startJob() {
		maintAlertManualService.startJob();
	}

	public String reStatistics() {
		boolean deleteFlag = this.deleteData();
		this.startJob();
		response.setContentType("text/html;charset=gbk");
		PrintWriter out;
		if (deleteFlag) {
			try {
				out = response.getWriter();
				out.print("success");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
			try {
				out = response.getWriter();
				out.print("fail");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
}
